package com.qianfeng.zhangwei.fruitday.fragment;


import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.qianfeng.zhangwei.fruitday.R;
import com.qianfeng.zhangwei.fruitday.adapter.AppFmPagerAdapter;

import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;

/**
 * 果食
 */
@EFragment(R.layout.fragment_guoshi)
public class FruitFragment extends BaseFragment implements ViewPager.OnPageChangeListener, RadioGroup.OnCheckedChangeListener {
    @ViewById(R.id.guoshi_viewpager)
    ViewPager viewPager;
    private AppFmPagerAdapter fmAdapter;
    private ArrayList<Fragment> fragments = new ArrayList<>();

    @ViewById(R.id.guoshi_rgs)
    RadioGroup fruitRgs;


    @Override
    public void injectBefore() {
        fragments.add(new BaikeFragment_());
        fragments.add(new GuoYouQuanFragment_());

    }

    @Override
    public void initView() {
        fmAdapter = new AppFmPagerAdapter(fragments, getChildFragmentManager());
        viewPager.setAdapter(fmAdapter);
        viewPager.addOnPageChangeListener(this);
        fruitRgs.setOnCheckedChangeListener(this);
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        RadioButton rb = (RadioButton) fruitRgs.getChildAt(position);
        rb.setChecked(true);

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.guoshi_baike_rb:
                viewPager.setCurrentItem(0);
                break;
            case R.id.guoshi_guoyou_rb:
                viewPager.setCurrentItem(1);
                break;
        }
    }
}
